import { cloneDeep } from "lodash";
import { getUserInfo } from "@/api/login.js";
const DEFAULTSTATE = {
  id: 0,
  name: "admin",
  superAdmin: 0,
  userInfo: {},
};

export default {
  namespaced: true,
  state: {
    ...cloneDeep(DEFAULTSTATE),
  },
  getters: {
    userInfo: (state) => state.userInfo || cloneDeep(DEFAULTSTATE.userInfo),
  },
  mutations: {
    set_userInfo(state, payload) {
      state.userInfo = payload;
    },
  },
  actions: {
    async get_userInfo({ commit, state }, params) {
      const res = await getUserInfo();
      commit("set_userInfo", res.data);
      return res;
    },
  },
};
